home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / SLBitmap.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  14.5 KB  |  511 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLBitmap.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef SLPALETE_H
  13. #include "SLPalete.h"
  14. #endif
  15.  
  16. #ifndef SLBITMAP_H
  17. #include "SLBitmap.h"
  18. #endif
  19.  
  20. #ifndef PRBITMAP_H
  21. #include "PRBitmap.h"
  22. #endif
  23.  
  24. #ifndef PRPICTUR_H
  25. #include "PRPictur.h"
  26. #endif
  27.  
  28. #ifndef FWODEXCE_H
  29. #include "FWODExce.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. #ifndef FWCOLOR_H
  37. #include "FWColor.h"
  38. #endif
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment FWGraphics_Bitmap
  42. #endif
  43.  
  44. //----------------------------------------------------------------------------------------
  45. //    FW_PrivBitmap_CreateFromBits
  46. //----------------------------------------------------------------------------------------
  47.  
  48. FW_HBitmap SL_API FW_PrivBitmap_CreateFromBits(
  49.                                 short width, short height, short pixelSize, FW_Palette palette,
  50.                                 void* image, long imageSize, short rowBytes,
  51.                                 FW_PlatformError* error)
  52. {
  53.     FW_ERR_TRY
  54.     {
  55.         return FW_NEW(FW_CPrivBitmapRep, (width, height, pixelSize, palette, image, imageSize, rowBytes));
  56.     }
  57.     FW_ERR_CATCH
  58.     return 0;    
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------
  62. //    FW_PrivBitmap_CreateFromPlatformBitmap
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_HBitmap SL_API FW_PrivBitmap_CreateFromPlatformBitmap(
  66.                                 FW_PlatformBitmap platformBitmap,
  67.                                 FW_PlatformError* error)
  68. {
  69.     FW_ERR_TRY
  70.     {
  71.         return FW_NEW(FW_CPrivBitmapRep, (platformBitmap));
  72.     }
  73.     FW_ERR_CATCH
  74.     return 0;    
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_PrivBitmap_CreateFromResource
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_HBitmap SL_API FW_PrivBitmap_CreateFromResource(
  82.                                 FW_OResourceFile* resourceFile,
  83.                                 FW_ResourceID resID,
  84.                                 FW_PlatformError* error)
  85. {
  86.     FW_ERR_TRY
  87.     {
  88.         return FW_NEW(FW_CPrivBitmapRep, (resourceFile, resID));
  89.     }
  90.     FW_ERR_CATCH
  91.     return 0;    
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_PrivBitmap_Copy
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_HBitmap SL_API FW_PrivBitmap_Copy(FW_HBitmap bitmap, const FW_SRect& srcRect, FW_PlatformError* error)
  99. {
  100.     FW_ASSERT(bitmap);
  101.     
  102.     FW_ERR_TRY
  103.     {
  104.         return FW_NEW(FW_CPrivBitmapRep, (*bitmap, srcRect));
  105.     }
  106.     FW_ERR_CATCH
  107.     return 0;    
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_PrivBitmap_IsEqual
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_Boolean SL_API FW_PrivBitmap_IsEqual(FW_HBitmap bitmap, FW_HBitmap bitmap2)
  115. {
  116.     FW_ASSERT(bitmap);
  117.     FW_ASSERT(bitmap2);
  118.  
  119.     // No try block necessary - Do not throw
  120.     return bitmap->IsEqual(*bitmap2);
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_PrivBitmap_Read
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_HBitmap SL_API FW_PrivBitmap_Read(
  128.                                 FW_HReadableStream    hStream,
  129.                                 FW_Boolean             bDIBFileHeader,
  130.                                 FW_PlatformError*     error)
  131. {
  132.     FW_ERR_TRY
  133.     {
  134.         FW_CReadableStream stream(hStream);
  135.         return FW_NEW(FW_CPrivBitmapRep, (stream, bDIBFileHeader));
  136.     }
  137.     FW_ERR_CATCH
  138.     return 0;    
  139. }
  140.     
  141. //----------------------------------------------------------------------------------------
  142. //    FW_PrivBitmap_Write
  143. //----------------------------------------------------------------------------------------
  144.  
  145. void SL_API FW_PrivBitmap_Write(
  146.                                 FW_HBitmap             bitmap,
  147.                                 FW_HWritableStream    hStream,
  148.                                 FW_Boolean             bDIBFileHeader,
  149.                                 FW_PlatformError*    error)
  150. {
  151.     FW_ASSERT(bitmap);
  152.  
  153.     FW_ERR_TRY
  154.     {
  155.         FW_CWritableStream stream(hStream);
  156.         bitmap->Write(stream, bDIBFileHeader);
  157.     }
  158.     FW_ERR_CATCH
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_PrivBitmap_Acquire
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void SL_API FW_PrivBitmap_Acquire(FW_HBitmap bitmap)
  166. {
  167.     FW_ASSERT(bitmap);
  168.  
  169.     // No try block necessary - Do not throw
  170.     bitmap->Acquire();
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_PrivBitmap_GetRefCount
  175. //----------------------------------------------------------------------------------------
  176.  
  177. long SL_API FW_PrivBitmap_GetRefCount(FW_HBitmap bitmap)
  178. {
  179.     FW_ASSERT(bitmap);
  180.  
  181.     // No try block necessary - Do not throw
  182.     return bitmap->GetRefCount();
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_PrivBitmap_Release
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void SL_API FW_PrivBitmap_Release(FW_HBitmap bitmap)
  190. {
  191.     FW_ASSERT(bitmap);
  192.  
  193.     // No try block necessary - Do not throw
  194.     bitmap->Release();
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_PrivBitmap_GetPlatformBitmap
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_PlatformBitmap SL_API FW_PrivBitmap_GetPlatformBitmap(FW_HBitmap bitmap)
  202. {
  203.     FW_ASSERT(bitmap);
  204.  
  205.     // No try block necessary - Do not throw
  206.     return bitmap->GetPlatformBitmap();
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_PrivBitmap_IsPlatformBitmapOrphan
  211. //----------------------------------------------------------------------------------------
  212.  
  213. FW_Boolean SL_API FW_PrivBitmap_IsPlatformBitmapOrphan(FW_HBitmap bitmap)
  214. {
  215.     FW_ASSERT(bitmap);
  216.  
  217.     // No try block necessary - Do not throw
  218.     return bitmap->IsPlatformBitmapOrphan();
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_PrivBitmap_OrphanPlatformBitmap
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_PlatformBitmap SL_API FW_PrivBitmap_OrphanPlatformBitmap(FW_HBitmap bitmap)
  226. {
  227.     FW_ASSERT(bitmap);
  228.  
  229.     // No try block necessary - Do not throw
  230.     return bitmap->OrphanPlatformBitmap();
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_PrivBitmap_SetPlatformBitmap
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_PlatformError SL_API FW_PrivBitmap_SetPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  238. {
  239.     FW_ASSERT(bitmap);
  240.  
  241.     // No try block necessary - Do not throw
  242.     bitmap->SetPlatformBitmap(newBitmap);
  243.     return FW_xNoError;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_PrivBitmap_AdoptPlatformBitmap
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_PlatformError SL_API FW_PrivBitmap_AdoptPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
  251. {
  252.     FW_ASSERT(bitmap);
  253.  
  254.     // No try block necessary - Do not throw
  255.     bitmap->AdoptPlatformBitmap(newBitmap);
  256.     return FW_xNoError;
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_PrivBitmap_GetPalette
  261. //----------------------------------------------------------------------------------------
  262.  
  263. FW_Palette SL_API FW_PrivBitmap_GetPalette(FW_HBitmap bitmap, FW_PlatformError* error)
  264. {
  265.     FW_ASSERT(bitmap);
  266.  
  267.     FW_ERR_TRY
  268.     {
  269.         return bitmap->GetPalette();
  270.     }
  271.     FW_ERR_CATCH
  272.     return NULL;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_PrivBitmap_SetPalette
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_PlatformError SL_API FW_PrivBitmap_SetPalette(FW_HBitmap bitmap, FW_Palette palette)
  280. {
  281.     FW_ASSERT(bitmap);
  282.  
  283.     FW_RETURN_ERR_TRY
  284.     {
  285.         bitmap->SetPalette(palette);
  286.     }
  287.     FW_RETURN_ERR_CATCH
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. //    FW_PrivBitmap_GetBitmapInfo
  292. //----------------------------------------------------------------------------------------
  293.  
  294. FW_PlatformError SL_API FW_PrivBitmap_GetBitmapInfo(
  295.                                 FW_HBitmap     bitmap,
  296.                                 short&        width,
  297.                                 short&        height, 
  298.                                 short&        rowBytes,
  299.                                 short&        pixelSize)
  300. {
  301.     FW_ASSERT(bitmap);
  302.  
  303.     // No try block necessary - Do not throw
  304.     bitmap->GetBitmapInfo(width, height, rowBytes, pixelSize);
  305.     return FW_xNoError;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_PrivBitmap_GetBitmapBoundsGC
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void SL_API FW_PrivBitmap_GetBitmapBoundsGC(Environment* ev, FW_HBitmap bitmap, FW_SGraphicContext& gc, FW_SRect& bounds)
  313. {
  314.     FW_ASSERT(bitmap);
  315.  
  316.     // No try block necessary - Do not throw
  317.     bitmap->GetBitmapBoundsGC(ev, gc, bounds);
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. //    FW_PrivBitmap_GetBitmapBounds
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void SL_API FW_PrivBitmap_GetBitmapBounds(FW_HBitmap bitmap, FW_SRect& bounds)
  325. {
  326.     FW_ASSERT(bitmap);
  327.  
  328.     bitmap->GetBitmapBounds(bounds);
  329. }
  330.  
  331. //----------------------------------------------------------------------------------------
  332. //    FW_PrivBitmap_GetPixelColor
  333. //----------------------------------------------------------------------------------------
  334.  
  335. void SL_API    FW_PrivBitmap_GetPixelColor(FW_HBitmap bitmap,
  336.                                         short horiz, 
  337.                                         short vert, 
  338.                                         FW_SColor& color)
  339. {
  340.     FW_ASSERT(bitmap);
  341.     
  342.     FW_CColor pixelColor;
  343.     bitmap->GetPixelColor(horiz, vert, pixelColor);
  344.     color = pixelColor;
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_PrivBitmap_SetPixelColor
  349. //----------------------------------------------------------------------------------------
  350.  
  351. void SL_API FW_PrivBitmap_SetPixelColor(FW_HBitmap bitmap,
  352.                                         short horiz,
  353.                                         short vert,
  354.                                         const FW_SColor& color)
  355. {
  356.     FW_ASSERT(bitmap);
  357.     
  358.     bitmap->SetPixelColor(horiz, vert, color);
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. //    FW_PrivBitmap_ChangeBitmap
  363. //----------------------------------------------------------------------------------------
  364.  
  365. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmap(FW_HBitmap     bitmap,
  366.                                         void*        image,
  367.                                         long        imageSize,
  368.                                         short        rowBytes,
  369.                                         short        width,
  370.                                         short        height, 
  371.                                         short        pixelSize,
  372.                                         FW_Boolean    bScale)
  373. {
  374.     FW_ASSERT(bitmap);
  375.  
  376.     // No try block necessary - Do not throw
  377.     return bitmap->ChangeBitmap(image, imageSize, rowBytes, width, height, pixelSize, bScale);
  378. }
  379.                                     
  380. //----------------------------------------------------------------------------------------
  381. //    FW_PrivBitmap_ChangeBitmapGeometry
  382. //----------------------------------------------------------------------------------------
  383.  
  384. FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmapGeometry(FW_HBitmap     bitmap,
  385.                                                 short        width,
  386.                                                 short        height, 
  387.                                                 short        pixelSize,
  388.                                                 FW_Boolean    bScale)
  389. {
  390.     FW_ASSERT(bitmap);
  391.  
  392.     // No try block necessary - Do not throw
  393.     return bitmap->ChangeBitmap(width, height, pixelSize, bScale);
  394. }
  395.                                     
  396. //----------------------------------------------------------------------------------------
  397. //    FW_PrivBitmap_SetImage
  398. //----------------------------------------------------------------------------------------
  399.  
  400. FW_PlatformError SL_API FW_PrivBitmap_SetImage(FW_HBitmap bitmap, 
  401.                                 void* image, 
  402.                                 long imageSize, 
  403.                                 short rowBytes)
  404. {
  405.     FW_ASSERT(bitmap);
  406.  
  407.     // No try block necessary - Do not throw
  408.     return bitmap->SetImage(image, imageSize, rowBytes);
  409. }
  410.  
  411. //----------------------------------------------------------------------------------------
  412. //    FW_PrivBitmap_CopyPixels
  413. //----------------------------------------------------------------------------------------
  414.  
  415. FW_PlatformError SL_API FW_PrivBitmap_CopyPixels(
  416.                                 FW_HBitmap    bitmapSrc, 
  417.                                 FW_HBitmap    bitmapDst,
  418.                                 FW_SRect&     boundsSrc, 
  419.                                 FW_SRect&    boundsDst)
  420. {
  421.     FW_ASSERT(bitmapSrc);
  422.     FW_ASSERT(bitmapDst);
  423.  
  424.     // No try block necessary - Do not throw
  425.     return bitmapSrc->CopyPixels(*bitmapDst, boundsSrc, boundsDst);
  426. }
  427.  
  428. #ifdef FW_BUILD_MAC
  429. //----------------------------------------------------------------------------------------
  430. //    FW_PrivBitmap_MacCreateFromPicture
  431. //----------------------------------------------------------------------------------------
  432.  
  433. FW_HBitmap SL_API FW_PrivBitmap_MacCreateFromPicture(
  434.                                 FW_HPicture picture, FW_SColor fillColor,
  435.                                 const FW_SRect& pictPart, FW_PlatformError* error)
  436. {
  437.     FW_ASSERT(picture);
  438.  
  439.     FW_ERR_TRY
  440.     {
  441.         return FW_NEW(FW_CPrivBitmapRep, (picture, fillColor, pictPart));
  442.     }
  443.     FW_ERR_CATCH
  444.     return NULL;
  445. }
  446. #endif
  447.  
  448. #ifdef FW_BUILD_MAC
  449. //----------------------------------------------------------------------------------------
  450. //    FW_PrivBitmap_MacGetAsPicture
  451. //----------------------------------------------------------------------------------------
  452.  
  453. FW_HPicture SL_API FW_PrivBitmap_MacGetAsPicture(FW_HBitmap bitmap, 
  454.                                                 const FW_SRect& bounds, 
  455.                                                 FW_PlatformError* error)
  456. {
  457.     FW_ASSERT(bitmap);
  458.  
  459.     FW_ERR_TRY
  460.     {
  461.         return bitmap->MacGetAsPicture(bounds);
  462.     }
  463.     FW_ERR_CATCH
  464.     return 0;
  465. }
  466. #endif
  467.  
  468. #ifdef FW_BUILD_MAC
  469. //----------------------------------------------------------------------------------------
  470. //    FW_PrivBitmap_MacLockPixels
  471. //----------------------------------------------------------------------------------------
  472.  
  473. PixMapHandle SL_API FW_PrivBitmap_MacLockPixels(FW_HBitmap bitmap)
  474. {
  475.     FW_ASSERT(bitmap);
  476.  
  477.     // No try block necessary - Do not throw
  478.     return bitmap->MacLockPixels();    // return NULL if fails
  479. }
  480. #endif
  481.  
  482. #ifdef FW_BUILD_MAC
  483. //----------------------------------------------------------------------------------------
  484. //    FW_PrivBitmap_MacUnlockPixels
  485. //----------------------------------------------------------------------------------------
  486.  
  487. FW_PlatformError SL_API FW_PrivBitmap_MacUnlockPixels(FW_HBitmap bitmap)
  488. {
  489.     FW_ASSERT(bitmap);
  490.  
  491.     // No try block necessary - Do not throw
  492.     bitmap->MacUnlockPixels();
  493.     return FW_xNoError;
  494. }
  495. #endif
  496.  
  497. #ifdef FW_BUILD_MAC
  498. //----------------------------------------------------------------------------------------
  499. //    FW_PrivBitmap_MacIsPixelsLocked
  500. //----------------------------------------------------------------------------------------
  501.  
  502. FW_Boolean SL_API FW_PrivBitmap_MacIsPixelsLocked(FW_HBitmap bitmap)
  503. {
  504.     FW_ASSERT(bitmap);
  505.  
  506.     // No try block necessary - Do not throw
  507.     return bitmap->MacIsPixelsLocked();
  508. }
  509.  
  510. #endif
  511.